package com.itheima.health.util;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @author ：贝
 * @date ：Created in 2022年06月07日
 * @description ：
 * 发送短信
 * @version: 1.0
 */
public class SMSUtils {
    public static void sendMessage(String signName,
                                   String templateCode,String phoneNumbers,String param){
        DefaultProfile profile = DefaultProfile
                .getProfile("cn-hangzhou",
                        "LTAI5tDf984QhozGewCkUwtb",//ID
                        "qekwQPGTOcN18nibYyTIZ2hn0zprQq");//Secret
        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setSysRegionId("cn-hangzhou");
        request.setPhoneNumbers(phoneNumbers);
        request.setSignName(signName);
        request.setTemplateCode(templateCode);
        request.setTemplateParam("{\"code\":\""+param+"\"}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(response.getMessage());
            if(response.getMessage().contains("OK")){
                System.out.println("短信发送成功");
            }
        }catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
